#!/usr/bin python3
# -*- coding:UTF-8 -*-
# Author: nigo
import plotly.graph_objects as go
import pandas as pd


# 数据
df = pd.DataFrame([
["0",785000.3136,6233305.906,2550087.434],
["1",663447.2369,1474453.377,2161913.495],
["2",544830.5425,1017369.783,1106571.396],
["3",509194.6006,886328.0422,873527.5098],
["4",503029.011,780999.9469,835981.5658],
["5",568517.6568,974911.3402,1384659.422],
["6",575106.1942,1995157.798,2162251.593],
["7",566139.5672,1671248.118,2786747.31],
["8",2891405.893,4568150.727,12901974.4],
["9",5623159.234,6250077.456,8695038.749],
["10",6331223.117,7673817.55,7394275.271],
["11",4912722.445,4588916.734,4236846.746],
["12",2397516.769,2610582.933,3499778.456],
["13",3396716.959,3072826.157,3273558.027],
["14",5389401.79,4705490.72,5070085.002],
["15",5994764.104,5106133.511,4266857.715],
["16",5212544.355,4206025.853,3959896.309],
["17",4201251.793,3401392.14,3215455.694],
["18",2137976.947,2118454.015,2484051.181],
["19",1498460.563,1753987.645,1911221.654],
["20",1391622.851,1455084.691,2013835.543],
["21",1299623.069,1431128.782,1622985.52],
["22",1234589.467,1343933.443,1597251.852],
["23",1073408.838,1386597.902,1412144.315]]
,columns=["小时数","2018年","2019年", "2020年" ])

# 轨迹
bar_2018 = go.Bar(x=df['小时数'],y=df['2018年'],name='2018年',text=df['2018年'])
bar_2019 = go.Bar(x=df['小时数'],y=df['2019年'],name='2019年',text=df['2019年'])
bar_2020 = go.Bar(x=df['小时数'],y=df['2020年'],name='2020年',text=df['2020年'])
# 画布
fig = go.Figure([bar_2018,bar_2019,bar_2020])
# 更新轨迹
fig.update_traces(texttemplate="%{text:.2s}",textposition='outside')
# 更新样式
fig.update_layout(title='销售金额小时分布图',xaxis_title='小时数',yaxis_title='销售金额',yaxis_tickformat=',.2r')
fig.update_layout(uniformtext_minsize=8, uniformtext_mode='hide')
# 显示画布
fig.show()
